/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmInformasiResepLuar.java
 *
 * Created on Feb 13, 2012, 12:06:07 PM
 */
package SIMRS.Apotek.view;

import SIMRS.Apotek.sql.KoneksiDatabase;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import usu.widget.Form;

/**
 *
 * @author yunniie
 */
public class frmInformasiResepLuar extends Form {
private static DefaultTableModel model;
    /** Creates new form frmInformasiResepLuar */
    public frmInformasiResepLuar() {
        initComponents();
        
        model=new DefaultTableModel();
        tblInformasiPelayananResepLuar.setModel(model);
        model.addColumn("No Resep");
        model.addColumn("Tanggal");
        model.addColumn("Nama Pembeli");
        model.addColumn("Alamat");
        model.addColumn("Umur");
        model.addColumn("Nama Obat");
        model.addColumn("Jumlah");
        model.addColumn("Harga");
        
        
        Date tanggal=new Date();
         tanggal.getDate();
        txtTanggalAwal.setDate(tanggal);
        txtTanggalAkhir.setDate(tanggal);
        
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/icon.png")).getImage());
        setTitle(".:: Form Pelayanan Resep Luar");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlUnder1 = new SIMRS.Apotek.widget.PnlUnder();
        label5 = new SIMRS.Apotek.widget.Label();
        label4 = new SIMRS.Apotek.widget.Label();
        btnCetak = new SIMRS.Apotek.widget.button2();
        btnUbah = new SIMRS.Apotek.widget.button2();
        btnTutup = new SIMRS.Apotek.widget.button2();
        scrollPane1 = new SIMRS.Apotek.widget.ScrollPane();
        tblInformasiPelayananResepLuar = new SIMRS.Apotek.widget.Table();
        label2 = new SIMRS.Apotek.widget.Label();
        txtTanggalAwal = new com.toedter.calendar.JDateChooser();
        label3 = new SIMRS.Apotek.widget.Label();
        txtTanggalAkhir = new com.toedter.calendar.JDateChooser();
        btnCari = new SIMRS.Apotek.widget.button2();

        setAnimationHide(usu.widget.constan.Animation.SHOW_FROM_TOP);
        setAnimationShow(usu.widget.constan.Animation.SHOW_FROM_BOTTOM);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlUnder1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(57, 190, 53), 3, true));
        pnlUnder1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label5.setForeground(new java.awt.Color(255, 255, 255));
        label5.setText("Informasi ");
        label5.setFont(new java.awt.Font("Tahoma", 1, 18));
        pnlUnder1.add(label5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 12, 400, 30));

        label4.setForeground(new java.awt.Color(255, 255, 255));
        label4.setText("Pelayanan Resep Luar");
        label4.setFont(new java.awt.Font("Tahoma", 1, 18));
        pnlUnder1.add(label4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 400, -1));

        btnCetak.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_cetak.png"))); // NOI18N
        btnCetak.setText("Cetak");
        pnlUnder1.add(btnCetak, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 380, -1, -1));

        btnUbah.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_edit.png"))); // NOI18N
        btnUbah.setText("Ubah");
        btnUbah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUbahActionPerformed(evt);
            }
        });
        pnlUnder1.add(btnUbah, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 380, -1, -1));

        btnTutup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_close.png"))); // NOI18N
        btnTutup.setText("Tutup");
        btnTutup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutupActionPerformed(evt);
            }
        });
        pnlUnder1.add(btnTutup, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 380, -1, -1));

        tblInformasiPelayananResepLuar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrollPane1.setViewportView(tblInformasiPelayananResepLuar);

        pnlUnder1.add(scrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, 550, 190));

        label2.setText("Periode");
        pnlUnder1.add(label2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 110, 92, -1));
        pnlUnder1.add(txtTanggalAwal, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, 120, -1));

        label3.setText("S/d");
        pnlUnder1.add(label3, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 130, -1, 21));
        pnlUnder1.add(txtTanggalAkhir, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 130, 120, -1));

        btnCari.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_search.png"))); // NOI18N
        btnCari.setText("Cari");
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });
        pnlUnder1.add(btnCari, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 120, 100, -1));

        getContentPane().add(pnlUnder1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 570, 430));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-572)/2, (screenSize.height-433)/2, 572, 433);
    }// </editor-fold>//GEN-END:initComponents

private void btnUbahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUbahActionPerformed
// TODO add your handling code here:
    input();
    
}//GEN-LAST:event_btnUbahActionPerformed

private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutupActionPerformed
    dispose();
}//GEN-LAST:event_btnTutupActionPerformed

private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariActionPerformed
// TODO add your handling code here:
    SimpleDateFormat Format=new SimpleDateFormat("yyyy-MM-dd");
    String tanggal1=Format.format(txtTanggalAwal.getDate());
    String tanggal2=Format.format(txtTanggalAkhir.getDate());
    
  model.getDataVector().removeAllElements();
    model.fireTableDataChanged();
    Connection c = KoneksiDatabase.getKoneksi();
    try {
        Statement s = c.createStatement();
        String sql = "SELECT pembeliobatluar.NoResep, resepobat.TglResep, pembeliobatluar.NamaPembeli, pembeliobatluar.Alamat, pembeliobatluar.UmurTahun, obat.NamaBarang, transaksiresepluar.JmlBarang, transaksiresepluar.Harga FROM pembeliobatluar JOIN resepobat ON (pembeliobatluar.NoResep=resepobat.NoResep) JOIN transaksiresepluar ON (pembeliobatluar.NoResep=transaksiresepluar.NoResep) JOIN obat ON (transaksiresepluar.KdBarang=obat.KdBarang) WHERE TglResep BETWEEN '"+tanggal1+"' AND '"+tanggal2+"'  ";
        ResultSet rs = s.executeQuery(sql);
        while (rs.next()) {

            Object[] o = new Object[8];

            o[0] = rs.getString("NoResep");
            o[1] = rs.getString("TglResep");
            o[2] = rs.getString("NamaPembeli");
            o[3] = rs.getString("Alamat");
            o[4] = rs.getString("UmurTahun");
            o[5] = rs.getString("NamaBarang");
            o[6] = rs.getString("JmlBarang");
            o[7] = rs.getString("Harga");


            model.addRow(o);
        }
        
        rs.close();
        
        
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(this, "Data Tidak Ditemukan");
        
    } 
}//GEN-LAST:event_btnCariActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private SIMRS.Apotek.widget.button2 btnCari;
    private SIMRS.Apotek.widget.button2 btnCetak;
    private SIMRS.Apotek.widget.button2 btnTutup;
    private SIMRS.Apotek.widget.button2 btnUbah;
    private SIMRS.Apotek.widget.Label label2;
    private SIMRS.Apotek.widget.Label label3;
    private SIMRS.Apotek.widget.Label label4;
    private SIMRS.Apotek.widget.Label label5;
    private SIMRS.Apotek.widget.PnlUnder pnlUnder1;
    private SIMRS.Apotek.widget.ScrollPane scrollPane1;
    private SIMRS.Apotek.widget.Table tblInformasiPelayananResepLuar;
    private com.toedter.calendar.JDateChooser txtTanggalAkhir;
    private com.toedter.calendar.JDateChooser txtTanggalAwal;
    // End of variables declaration//GEN-END:variables

public void input() {
    int i = tblInformasiPelayananResepLuar.getSelectedRow();
        if(i==-1){
            return;
        }
       
        String noResep=tblInformasiPelayananResepLuar.getValueAt(i, 0).toString();    
        String namaPembeli= tblInformasiPelayananResepLuar.getValueAt(i, 2).toString();
        String alamat=tblInformasiPelayananResepLuar.getValueAt(i, 3).toString();
        String umur=tblInformasiPelayananResepLuar.getValueAt(i, 4).toString();
         
        Connection c=KoneksiDatabase.getKoneksi();
         

        SimpleDateFormat tgl = new SimpleDateFormat("yyyy-MM-dd");
                Date a = null;

                String tanggal = tblInformasiPelayananResepLuar.getValueAt(i, 1).toString();
                try {
                    a = tgl.parse(tanggal);
                } catch (ParseException e) {
                   
                }
    
      String NamaBarang=tblInformasiPelayananResepLuar.getValueAt(i, 5).toString();
       String JmlBarang=tblInformasiPelayananResepLuar.getValueAt(i, 6).toString();
       String harga=tblInformasiPelayananResepLuar.getValueAt(i, 7).toString();
       
    frmPelayananResepLuar form= new frmPelayananResepLuar();
    form.isiText(noResep, namaPembeli, alamat, umur, a, NamaBarang, JmlBarang, harga, harga);
    form.setVisible(true);

}

}
